﻿// ———————————————————————–
// <copyright file="Program.cs" company="The MITRE Corporation">
//    Copyright (c) 2010 The MITRE Corporation. All rights reserved.
// </copyright>
// ———————————————————————–
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)
                
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace HttpLoader
{
  /// <summary>
  /// Program Class
  /// </summary>
  public static class Program
  {
      [DllImport("kernel32.dll")]
      static extern bool AttachConsole(int dwProcessId);
      private const int ATTACH_PARENT_PROCESS = -1;

      [DllImport("kernel32.dll")]
      static extern bool FreeConsole();

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    public static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new HttpLoaderMain());
        }
        else if (args[0] == "clone" && args.Length==3) // clone operation copies all DEs from one server to another
        {
            AttachConsole(ATTACH_PARENT_PROCESS);
            new RouterCloner().send(args[1], args[2]); //arg1 is source, arg2 is destination. example: httpLoader.exe clone http://icnet-test.mitre.org http://icnet-staging.mitre.org
            FreeConsole();
            return;
        }
    }
  }
}
